import keyboard

keyboard.add_hotkey('F5', print, args=('aaa',))
keyboard.add_hotkey('alt', print, args=('bbb',))

recorded = keyboard.record(until='esc')
#当按下esc时结束按键监听，并输出所有按键事件
print(recorded)